//
//  WelcomeViewController.m
//  OC-微博
//
//  Created by Apple on 15/11/11.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "WelcomeViewController.h"
@interface WelcomeViewController ()
//背景图片
@property (nonatomic, strong) UIImageView *BackImageView;
//头像
@property (nonatomic, strong) UIImageView *iconView;
//文字
@property (nonatomic, strong) UILabel *textLable;

@end

@implementation WelcomeViewController
#pragma mark /*******************  视图生命周期  *******************/
- (void)loadView {
    self.view = self.BackImageView;
    [self setUpUI];
}

- (void)viewDidAppear:(BOOL)animated   {
    [super viewDidAppear:animated];
//     //更改约束
    [self.iconView updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.bottom).offset(-self.view.bounds.size.height + 200);
    }];
    //设置动画
    
    self.textLable.alpha = 0;
    [UIView animateWithDuration:1.2 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:10 options:0 animations:^{
        //更改约束
        [self.view layoutIfNeeded];
        //[self.iconView layoutIfNeeded] 重新布局自身 ，没有动画效果
    } completion:^(BOOL finished) {
      [UIView animateWithDuration:0.8 animations:^{
            self.textLable.alpha = 1;
        } completion:^(BOOL finished) {
             //切换视图  发送通知
            [[NSNotificationCenter defaultCenter] postNotificationName:WBSwitchRootViewControllerNotification object:nil];
        }];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
       //异步加载用户头像
      //[SDWebImageRetryFailed, SDWebImageRefreshCached]]
    [self.iconView sd_setImageWithURL:[UserAccountViewModel shardViewModel].avatarUrl placeholderImage:[UIImage imageNamed:@"avatar_default_big"] options:SDWebImageRetryFailed | SDWebImageRefreshCached];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
#pragma mark /*******************  懒加载  *******************/
-(UIImageView *)BackImageView {
    
    if (_BackImageView == nil) {
        _BackImageView = [UIImageView setImageName:@"ad_background"];
    }
    return _BackImageView;
}
-(UIImageView *)iconView {
    
    if (_iconView == nil) {
        _iconView = [UIImageView setImagName:@"avatar_default_big"];
    }
    return _iconView;
}

-(UILabel *)textLable {
   if (_textLable == nil) {
        _textLable = [[UILabel alloc]initLabelTitle:[NSString stringWithFormat:@"欢迎回来%@",[UserAccountViewModel shardViewModel].account.screen_name]labelFont:18 screenInset:0];    }
    return _textLable;
}
#pragma mark /*******************  添加子控件  *******************/
- (void)setUpUI {
   //1.添加控件
    [self.view addSubview:self.iconView];
    [self.view addSubview:self.textLable];
    //2.自动布局
    [self.iconView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-200);
        make.width.height.equalTo(90);
    }];
    [self.textLable makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView);
        make.top.equalTo(self.iconView.bottom).offset(16);
    }];
}

@end
